package com.wenhai.exercise;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleDemo {
    public static void main(String[] args) throws InterruptedException {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(8);
//        scheduledExecutorService.scheduleAtFixedRate(() -> {
//            long start = System.currentTimeMillis();
//            System.out.println("==============scheduleAfFixedRate start===== ");
//            try {
//                TimeUnit.SECONDS.sleep(4);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            System.out.println("==============scheduleAfFixedRate end " + (System.currentTimeMillis() - start) + " ===== ");
//        }, 1, 6, TimeUnit.SECONDS);
        scheduledExecutorService.scheduleWithFixedDelay(() -> {
            long start = System.currentTimeMillis();
            System.out.println("==============scheduleAfFixedDelay start===== ");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("==============scheduleAfFixedDelay end " + (System.currentTimeMillis() - start) + "===== ");
        }, 1, 4, TimeUnit.SECONDS);

        TimeUnit.SECONDS.sleep(99999999);
    }
}
